process.env.VUE_APP_NAME=require('./package.json').name;
process.env.VUE_APP_VERSION=require('./package.json').version;
process.env.VUE_APP_AUTHOR=require('./package.json').author;

const tsImportPluginFactory=require('ts-import-plugin');

const pages={
	index:'doc/main.js',
};
for(const key of Object.keys(pages)){
	const val={
		chunks:[
			'base',
			'quasar',
			'viewDesigsn',
			'lib',
			'components',
			'initial',
			key,
		],
	};
	if(typeof pages[key]==='string'){
		pages[key]=Object.assign({entry:pages[key]},val);
	}else{
		Object.assign(pages[key],val);
	}
}

let devServer={};
if(process.env.VUE_APP_PROXY_HOST){
	devServer={
		proxy:{
			'/seeyon/':{
				target:process.env.VUE_APP_PROXY_HOST
			},
			'/lexmis/rest/':{
				target:process.env.VUE_APP_PROXY_HOST
			},
		}
	};
}

module.exports={
	publicPath:'./',
	outputDir:'dist',
	assetsDir:'assets',
	// indexPath:'index.html',
	filenameHashing:true,

	pages,

	lintOnSave:'warning',
	runtimeCompiler:false,

	transpileDependencies:[
		'view-design',
		'quasar',
		'threads',
		'debug',
		'observable-fns',
		'is-observable',
		'highlight.js',
	],

	productionSourceMap:false,

	devServer,

	chainWebpack:(config) => {
		config.resolve.extensions
			.add('.tsx')
			.add('.ts');
		config.output
			// .libraryExport('default')
			.jsonpFunction('lexmisBaseuiWebpackJsonp');
		config.module
			.rule('typescript')
			.test(/\.tsx?$/)
			.use('cache-loader')
			.loader('cache-loader')
			.end()
			.use('babel-loader')
			.loader('babel-loader')
			.end()
			.use('ts-loader')
			.loader('ts-loader')
			.options({
				transpileOnly:true,
				getCustomTransformers:() => ({
					before:[tsImportPluginFactory([
						{libraryName:'view-design',libraryDirectory:'src/components'},
						{libraryName:'lodash',libraryDirectory:'./',camel2DashComponentName:false},
					])]
				})
			});
		config.module
			.rule('js')
			.test(/(?<!\.worker)\.m?jsx?$/);
		config.module
			.rule('worker-loader')
			.test(/\.worker\.js$/)
			.use('worker-loader')
			.loader('worker-loader')
			.end()
			.use('cache-loader')
			.loader('cache-loader')
			.end()
			.use('babel-loader')
			.loader('babel-loader');
		config.optimization.splitChunks({
			chunks:'all',
			minSize:0,
			cacheGroups:{
				//vue,vuex,vue-router,core-js等基础脚本
				base:{
					priority:11,
					test:/[\\/]node_modules[\\/](vue(x|-router)?|core-js)[\\/]/,
					name:'base',
					reuseExistingChunk:true,
					enforce:true,
				},
				quasar:{
					priority:11,
					test:/[\\/]node_modules[\\/]quasar[\\/]/,
					name:'quasar',
					reuseExistingChunk:true,
					enforce:true,
				},
				viewDesigsn:{
					priority:11,
					test:/[\\/]node_modules[\\/]view-design[\\/]/,
					name:'viewDesigsn',
					reuseExistingChunk:true,
					enforce:true,
				},
				lib:{
					priority:10,
					test:/[\\/]node_modules[\\/]/,
					name:'lib',
					reuseExistingChunk:true,
					enforce:true,
				},
				components:{
					priority:9,
					test:/[\\/]src[\\/]/,
					name:'components',
					reuseExistingChunk:true,
					enforce:true,
				},
				initial:{
					priority:7,
					name:'initial',
					chunks:'initial',
					reuseExistingChunk:true,
					enforce:true,
				},
			}
		});
		if(process.env.NODE_ENV==='production'){
			config.optimization.minimizer('terser').tap((args) => {
				args[0].terserOptions.compress.drop_console=true;
				args[0].terserOptions.compress.keep_infinity=true;
				return args;
			});
		}
		config.resolve.alias.set('quasar$','@lexmis/quasar');
	},

	pluginOptions:{
		quasar:{
			importStrategy:'kebab',
			rtlSupport:false
		}
	}
};
